<template>
  <div>
    <el-select
      :loading="loading"
      v-model="value"
      placeholder="Select"
      size="large"
      style="width: 240px"
    >
      <el-option
        v-for="item in options"
        :key="item.value"
        :label="item.label"
        :value="item.value"
      />
    </el-select>
  </div>
</template>
<script setup lang="ts">
import { useFetchSelect } from "@/hooks/useFetchSelect";

const value = ref("");

const getRemoteData = () => {
  return new Promise<any[]>((resolve, reject) => {
    setTimeout(() => {
      if (Math.random() > 0) {
        resolve([
          {
            value: "Option1",
            label: "Option1",
          },
          {
            value: "Option2",
            label: "Option2",
          },
          {
            value: "Option3",
            label: "Option3",
          },
          {
            value: "Option4",
            label: "Option4",
          },
          {
            value: "Option5",
            label: "Option5",
          },
        ]);
      } else {
        reject(new Error("不小心出错了！"));
      }
    }, 1500);
  });
};
const selectResult = useFetchSelect({ apiFun: getRemoteData });
const { loading, options } = toRefs(selectResult);
</script>
<style lang="scss" scoped></style>
